package semantic_compute.relation_extraction.yago_matcher;

import com.univocity.parsers.tsv.TsvParser;
import com.univocity.parsers.tsv.TsvParserSettings;
import knowlwdge_graph.knowledge_etl.yago_etl.ExtractorTSVFiles;
import knowlwdge_graph.knowledge_etl.yago_etl.RowYagoTriple;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by julianzliu on 4/23/2017.
 */
public class ExtractorFromPatty {


    public ExtractorFromPatty(){

    }


    public List<RowYagoTriple> getAllTripleByTSVParser(String file){
        File f = new File(file);
        TsvParserSettings settings = new TsvParserSettings();
        settings.getFormat().setLineSeparator("\n");
        // creates a TSV parser
        TsvParser parser = new TsvParser(settings);
        // parses all rows in one go.
        List<String[]> allRows = parser.parseAll(f);


        List<RowYagoTriple> rows = new ArrayList<>();
        System.out.println("rowsNum = " + allRows.size());
        for(String[] row:allRows){
            RowYagoTriple triple = parseRowToTripe( row );
            rows.add( triple );
            System.out.println(triple.subject + " " + triple.predicate + " " + triple.object);
        }
        return rows;
    }

    private RowYagoTriple parseRowToTripe(String[] cols){
        //System.out.println("size = " + cols.length);
        //System.out.println(cols[0] + "|" + cols[1] + "|" + cols[2] + "|" + cols[3] + "|" + cols[4]);
        String id = "";
        Float value = 0.0f;
        String relation = "<hasPatty>";
        String subject = cols[0];
        subject = "<" + subject + ">";
        String object = cols[1];
        return new RowYagoTriple(
                id,subject.replace("'","\\'"),relation,object.replace("'","\\'"),value
        );
    }



    /*********************************************
     * MAIN
     */
    public static void main(String[] args){
        String file = "D:\\GitRepos\\semantic-fulltext-search-engine\\e12.semantic-computing\\src\\main\\java\\semantic_compute\\relation_extraction\\yago_matcher\\patty\\yago-relation-paraphrases.txt";

        ExtractorFromPatty extractorFromPatty = new ExtractorFromPatty();

        extractorFromPatty.getAllTripleByTSVParser( file );

    }



}
